/*
* GeoVISTA Center (Penn State, Dept. of Geography)
* Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
* All Rights Researved.
*
* Each element of the group is a DataIDSet. So the relationship is:
* DataIDGroup contain DataSetGroup, which contain record ID
* @author: jin Chen
* @date: Oct 2, 2003$
* @version: 1.0
*/
package edu.psu.geovista.app.pcp.toolkits.group;

import edu.psu.geovista.group.IndexSet;
import edu.psu.geovista.group.MapGroup;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class DataIDGroup extends ObjectGroup implements MapGroup{

    /* public DataIDSet getByIndex(int index) {
    Iterator iter=this.iterator() ;
    while(iter.hasNext() ){
    DataIDSet axis=(DataIDSet)iter.next() ;
    if (axis.getIndex()==index){
    return axis;
    }
    }
    return null;
    }*/
    /**
     *
     * @param id  DataIDSet's ID, not record ID
     * @return
     */
    public IndexSet getIndexSet(Object id){
        return (DataIDSet) super.getByID(id);

    }

    public void add(IndexSet idset) {
        groups.put(idset.getId(),idset);
    }
    /* public HashSet getRecordIds(int DataSetID){

    }*/
    /**
     * @param DataSetIDs    ids of DataSet ( 
     * @return              record ids belonged to these DataSet
     */
    public Set getIndice(int[] DataSetIDs){

        HashSet recordIds=new HashSet();
        ArrayList grpList=this.getIndexSortList();
        for (int i=0;i<DataSetIDs.length ;i++){
            DataIDSet idSet=(DataIDSet) grpList.get(DataSetIDs[i]);
            HashSet ids = (HashSet) idSet.getIdAsSet();
            HashSet ctgIds=(HashSet) ids.clone() ;
            recordIds.addAll(ctgIds);
        }
        return recordIds;

    }
    /**
     *
     * @return  record ids belonged to the DataIDGroup
     */
    public Set getAllIndice(){
        int[] DataSetIDs=new int[groups.size() ];
        for (int i=0;i<DataSetIDs.length ;i++){
            DataSetIDs[i]=i;
        }
        return this.getIndice(DataSetIDs);
    }

}
